using System;
using System.Linq;
using System.Collections.Generic;
using DevExpress.CodeRush.StructuralParser;

namespace CR.StyleCop.Naming {

    public class AccessibleFieldsMustBeginWithUpperCaseLetter : BaseStyleCopIssueSearcher<IFieldElement> {

        public override IEnumerable<StyleCopIssue> FindIssues(IEnumerable<IFieldElement> elements) {
            return elements.Where(f => f.Visibility == MemberVisibility.Public || f.Visibility == MemberVisibility.Internal)
                                 .Where(f => char.IsLower(f.Name[0]) && char.IsLetter(f.Name[0]))
                                 .Select(e => new StyleCopIssue {
                                     Element = e,
                                     IssueDescription = Resource.AccessibleFieldsMustBeginWithUpperCaseLetterIssueDescription
                                 });
        }
    }
}